package com.example.xm.ui.home.fragments;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.xm.R;
import com.example.xm.adapter.HomeAdapter.HomePhotoAdapter;
import com.example.xm.base.BaseAdapter;
import com.example.xm.base.BaseFragment;
import com.example.xm.bean.HomeBean.HomeArticleBean;
import com.example.xm.bean.HomeBean.HomeBannderBean;
import com.example.xm.bean.HomeBean.HomeHotUserBean;
import com.example.xm.bean.HomeBean.HomePhotoBean;
import com.example.xm.bean.HomeBean.HomeRecommendBean;
import com.example.xm.bean.HomeBean.HomeRewardBean;
import com.example.xm.bean.HomeBean.HomeSquareBean;
import com.example.xm.bean.HomeBean.HomeTopicDiscussedBean;
import com.example.xm.bean.HomeBean.HomeVideoBean;
import com.example.xm.interfaces.home.IHome;
import com.example.xm.presenter.home.RecommendPresenter;
import com.example.xm.ui.home.fragments.activity_photo.PhotoActivity;

import java.util.ArrayList;

import butterknife.BindView;

public class Fragment_Photo extends BaseFragment<IHome.RecommendPersenter> implements IHome.RecommendView {

    @BindView(R.id.tv_tab_all)
    TextView tvTabAll;
    @BindView(R.id.tv_tab_fujin)
    TextView tvTabFujin;
    @BindView(R.id.v)
    View v;
    @BindView(R.id.rlv_photo)
    RecyclerView rlvPhoto;
    private ArrayList<HomePhotoBean.DataBean.DynamicsBean> list;
    private HomePhotoAdapter homePhotoAdapter;

    @Override
    protected IHome.RecommendPersenter initPresenter() {
        return new RecommendPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_photo;
    }

    @Override
    protected void initView() {
        list = new ArrayList<>();
        rlvPhoto.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        homePhotoAdapter = new HomePhotoAdapter(getActivity(), list);
        rlvPhoto.setAdapter(homePhotoAdapter);
        homePhotoAdapter.setOnClick(new BaseAdapter.onClick() {
            @Override
            public void click(int pos) {
                Intent intent = new Intent(getActivity(), PhotoActivity.class);
                HomePhotoBean.DataBean.DynamicsBean bean = list.get(pos);
                intent.putExtra("bean",bean);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initData() {
        mPresenter.getPhoto();
    }

    @Override
    protected void initListener() {

    }

    @Override
    public void showTips(String tips) {

    }

    @Override
    public void showLoading(int visble) {

    }

    @Override
    public void getBannerReturn(HomeBannderBean result) {

    }

    @Override
    public void getTopicDiscussedReturn(HomeTopicDiscussedBean result) {

    }

    @Override
    public void getRecommendReturn(HomeRecommendBean result) {

    }

    @Override
    public void getHotUserReturn(HomeHotUserBean result) {

    }

    @Override
    public void getSquareReturn(HomeSquareBean result) {

    }

    @Override
    public void getVideoReturn(HomeVideoBean result) {

    }

    @Override
    public void getPhotoReturn(HomePhotoBean result) {
        if (result.getStatus().getStatusCode() == 100){
            list.addAll(result.getData().getDynamics());
            homePhotoAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getHomeArticleReturn(HomeArticleBean result) {

    }

    @Override
    public void getHomeRewardReturn(HomeRewardBean result) {

    }
}
